<?php
require ("Conexion.php");
class Coordenadas{

 private $datos;
 private $id;

 function  __construct($datos,$id) {
     $this->datos = $datos;
     $this->id = $id;

 }

 function getDatos() {
     return $this->datos;
 }
 function getId(){
     return $this->id;
 }


 function Insertar(){

    $conexion = new Conexion();
    $query = "SELECT last_insert_id()";

    if(!$query = @ mysql_query($query,$conexion->link)){
 	echo "Error";
 	exit(-1);
    }

    $row = mysql_fetch_array($query);
    //$packed = $_POST['data'];
    //$data = split(";",$packed);
    $data = split(";",$this->getDatos());

    for($i = 0; $i < count($data)-1; $i++) {
	$dat = split(",",$data[$i]);
        //"INSERT INTO coordenadas VALUES(".$row[0].",".$dat[0].",".$dat[1].",'{$i}')";
        $query = "INSERT INTO coordenadas VALUES('{$this->getId()}',".$dat[0].",".$dat[1].",'{$i}')";

        if(!mysql_query($query,$conexion->link)){
		echo "Error al insertar";
	}
    }
 }
 function Eliminar(){

    $conexion = new Conexion();
    $query = "SELECT last_insert_id()";

    if(!$query = @ mysql_query($query,$conexion->link)){
 	echo "Error";
 	exit(-1);
    }

    $row = mysql_fetch_array($query);
    //$packed = $_POST['data'];
    //$data = split(";",$packed);
    $data = split(";",$this->datos);
           //////////////////////////////
                    //OJO//
    /////////////////////////////////////
    $query = "DELETE FROM coordenadas WHERE id = '{$this->getId()}' ";

    if(!mysql_query($query,$conexion->link)){
        echo "Error al insertar";
    }
 }

}
?>
